import request from '@/utils/request'
import { CommonSearch } from '@/config/list'
import { StarTreeNode } from '@/model/common/tree/model'
import { CodeList, CodeBeanData } from '@/model/system/code/model'

export function loadCodeTree () {
  return request<StarTreeNode[]>({
    url: '/starCode/loadTree'
  })
}

export function loadCodeListByFid (data: CommonSearch) {
  return request<CodeList>({
    url: '/starCode/loadCodeListByFid',
    data: data,
    method: 'post'
  })
}

export function loadCodeById (id: string) {
  return request<CodeBeanData>({
    url: `/starCode/loadCodeById?id=${id}`
  })
}

export function deleteCode (id: string, type: string) {
  return request({
    url: `/starCode/removeCode?codeId=${id}&type=${type}`,
    method: 'post'
  })
}

export function saveCode (formData: CodeBeanData) {
  return request({
    url: '/starCode/saveCode',
    data: formData,
    method: 'post'
  })
}

export function getMaxIndex (fid: string) {
  return request({
    url: `/starCode/getMaxIndex?fid=${fid}`
  })
}

export function getCode (fid: string) {
  return request({
    url: `/starCode/getCode?fid=${fid}`
  })
}

export function getCodeTree (fids: string) {
  return request({
    url: `/starCode/getCodeByTree?fids=${fids}`,
    method: 'post'
  })
}

export function getCodeGroupTree () {
  return request({
    url: '/starCode/getCodeGroupTree'
  })
}
